﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using CannedHeater.ViewModel;

namespace CannedHeater.View
{
    /// <summary>
    /// View for displaying status and latest data from netduino device, and sending commands to it
    /// </summary>
    public partial class ControlView : UserControl
    {
        public ControlView()
        {
            InitializeComponent();
        }

        private void SettingsBtn_Click(object sender, RoutedEventArgs e)
        {
            ApplicationController.Default.NavigateTo(ViewType.Settings);
        }

        private void ConnectSendCmdBtn_Click(object sender, RoutedEventArgs e)
        {
            ControlViewModel CVM = ((Button)sender).DataContext as ControlViewModel;
            if (CVM != null) CVM.ConnectOrExecCommand();
        }
    }

    /// <summary>
    /// Sets the text according to whether or not the app is currently connected to the netduino device
    /// </summary>
    public class CmdBtnTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return "Connect";

            bool b = (bool)value;
            return b ? "Send Command" : "Connect";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null; // Not needed
        }
    }
}
